<template>
  <view>
    <div class="login">
      <div class="login-form">
        <!-- <h3 class="title">登录</h3> -->

        <div v-if="!loading" style="text-align: center" class="pb20">
          <u-empty mode="permission" v-if="!loading" text="未获取到授权信息，请返回重新授权登录">
          </u-empty>
          <navigator url="login" hover-class="navigator-hover" class="login-btn ">
            返回登录
          </navigator>
        </div>
        <div v-else class="loading">登 录 中...</div>
      </div>
    </div>
  </view>
</template>

<script>
  import {
    getQueryObject
  } from '@/utils/common.js'

  export default {
    data() {
      return {
        callbackQuery: undefined,
        redirect: '',
        authSource: '',
        loading: false
      }
    },
    onReady() {
      this.callbackQuery = getQueryObject()
      this.authSource = this.callbackQuery.authSource
      var that = this
      if (this.callbackQuery && this.callbackQuery.state != null) {
        this.loading = true
        this.$store.dispatch('oauthLogin', this.callbackQuery).then(res => {
          this.loginSuccess()
        }).catch((err) => {
          console.log(err)
          this.$modal.msgError(err.msg)
          this.loading = false
        });
      }
    },
    methods: {
      // 登录成功后，处理函数
      loginSuccess(result) {
        // 设置用户信息
        this.$store.dispatch('GetInfo').then(res => {
          this.$tab.reLaunch('/pages/index')
        })
      },
    }
  }
</script>

<style>
  .loading {
    text-align: center;
    color: #ccc;
    padding: 10px;
  }

  .login-btn {
    margin-top: 40px;
    height: 45px;
  }

  .pb20 {
    margin: 60px;
  }
</style>